from ..database import database
from ..models.client import Client


class ClientService(object):
    @classmethod
    def create(cls,
               name,
               client_id,
               client_secret,
               redirect_uris,
               default_scopes,
               is_confidential=False,
               description=None):
        client = Client(
            name = name,
            client_id=client_id,
            client_secret=client_secret,
            _redirect_uris=redirect_uris,
            _default_scopes=default_scopes,
            is_confidential=is_confidential,
            description=description
        )
        database.session.add(client)
        database.session.commit()

    @classmethod
    def delete(cls, client):
        database.session.delete(client)
        database.session.commit()

    @classmethod
    def get_by_client_id(cls, client_id):
        return Client.query.filter(Client.client_id == client_id).first()
